package www.xpu.edu.app;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import java.util.ArrayList;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class Activity_talk extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //取消标题栏
        ActionBar actionbar=getSupportActionBar();
        if(actionbar!=null)
        {
            actionbar.hide();
        }
        //迫不得已而为之



        setContentView(R.layout.activity_talk);



    }
    //手机热点局域网ip 192.168.43.188
    private void sendRequest()
    {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    OkHttpClient client=new OkHttpClient();
                    Request request=new Request.Builder()
                            .url("http://188.131.250.4:8080/test20190329/select0403")
                            .build();
                    Response response=client.newCall(request).execute();
                    String responseData=response.body().string();
                    List<JavaBean> list=new ArrayList<JavaBean>();
                    list=JSON.parseObject(responseData,new TypeReference<List<JavaBean>>(){});
                    List<Talk> talkList=new ArrayList<>();
                    for (int i = 0; i < list.size(); i++) {
                        talkList.add(new Talk(R.drawable.logo_lantian,list.get(i).getName(),"西安工程大学-"+(i+1)+"号楼",list.get(i).getTime(),list.get(i).getContext()));
                    }
                    TalkAdapter adapter=new TalkAdapter(Activity_talk.this,R.layout.talk_list_layout,talkList);
                    ListView listView=(ListView)findViewById(R.id.talk_list);
                    listView.setAdapter(adapter);
                    final List<JavaBean> finalList = list;
                    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            String test= finalList.get(position).getContext();
                            Toast.makeText(Activity_talk.this,"详细内容->"+test,Toast.LENGTH_LONG).show();
                        }
                    });


                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }).start();

    }
}
